fix(nextjs): Use absolute path for distDir
in webpack plugin options
#6214
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In nextjs, the output directory (
distDir
) is specified by the user and stored in memory as a relative path. It's then used in two places:In the nextjs SDK, we also use the value in two places:
@sentry/cli
via Sentry webpack plugin options.sentry/cli
then resolves it against its working directory, so that it knows where to find built files to upload.global.__rewriteFramesDistDir__
(where we've stashed it at build time via our prefix loader), and then resolve it against the working directory, so theRewriteFrames
integration knows what value to strip from stackframe paths.At runtime, this resolution always works, because it matches what nextjs itself does. At build time, it also works... most of the time. But in the case where the project directory and
@sentry/cli
's working directory don't match, it leads to@sentry/cli
not being able to find the files it needs to upload. (This can happen if, for example, the app is a package in a monorepo - located atpackages/nextjsApp
, say - and@sentry/cli
is running from the monorepo's root levelnode_modules
.)This fixes that by resolving the
distDir
value against the project directory (thereby turning it into an absolute path) before passing it to@sentry/cli
. That way, no resolution on@sentry/cli
's part is necessary, preventing the mismatch.Fixes the problem outlined in #6194.